import config, { setConfig } from './config';
import { isAccountOnline, login } from './api/sign';
import Local from './utils/local';
import PL from 'popoload';
import router from 'umi/router';

export const dva = {
  config: {
    onError(err) {
      err.preventDefault();
    },
  },
};

export function render(oldRender) {
  const host = (window.ATCONFIG && window.ATCONFIG.host) || DEV_HOST || (location.origin + '/');
  setConfig({ host });
  isAccountOnline((isOnLine) => {
    if (!isOnLine) {
      Local.clear();
      login({
        name: 'dmdz',
        password: '1234',
        success: data => {
          router.push('/admin');
        },
        error: data => {
          router.push('/admin');
        }
      });

    } else {
      // router.push("/login");
      router.push('/admin');
    }
    if (window.PAGE_SPINNER) {
      window.PAGE_SPINNER.spin();
    }
    oldRender();
  });
}